package com.mtzqc.common.manager

import com.mtzqc.common.kt.loadService
import com.mtzqc.common.service.JsonService

object JsonManager {
    
    val service: JsonService by lazy {
        loadService()
    }

    fun toJson(value: Any?): String? {
        return value?.let {
            service.toJson(it)
        }
    }

    inline fun <reified T> pareJson(json: String?): T? {
        return fromJson(json, T::class.java)
    }

    fun <T> fromJson(json: String?, clazz: Class<T>): T? {
        return json?.let {
            service.pare(it, clazz)
        }
    }

    inline fun <reified T> pareJsonArray(json: String?): List<T>? {
        return fromJsonArray(json, T::class.java)
    }

    fun <T> fromJsonArray(json: String?, clazz: Class<T>): List<T>? {
        return json?.let {
            service.pareList(it, clazz)
        }
    }
}